home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / PcodeObject.h < prev    next >
Text File  |  1994-12-27  |  12KB  |  359 lines

  1. /* PcodeObject.h */
  2.  
  3. #ifndef Included_PcodeObject_h
  4. #define Included_PcodeObject_h
  5.  
  6. /* PcodeObject module depends on */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* Memory */
  12. /* DataMunging */
  13.  
  14. /* Stack indices are non-positive:  0 is the word on the */
  15. /* top of the stack and descending values (-1, -2, -3, ...) are words further */
  16. /* from the top of stack. */
  17. typedef enum
  18.     {
  19.         /* Unlinked function call.  The function's name is known from compile time, but */
  20.         /* the address has not been linked.  The first parameter is the name of the */
  21.         /* function (a string).  The second parameter is the list of types of the */
  22.         /* parameters for the function in question.  The third parameter */
  23.         /* is the return type of the function.  The return address is pushed */
  24.         /* onto the stack */
  25.         epFuncCallUnresolved EXECUTE(= 16000),
  26.             /* <opcode> ^"<functionname>" ^[paramlist] <returntype> <reserved> */
  27.  
  28.         /* Linked function call.  The opcode epFuncCallUnresolved is converted to this */
  29.         /* when first encountered and successfully linked.  The first parameter is not */
  30.         /* changed.  The second parameter is released and converted to a pointer to */
  31.         /* the appropriate function's PcodeRec.  The third parameter */
  32.         /* is the return type of the function.  The return address is pushed */
  33.         /* onto the stack */
  34.         epFuncCallResolved,
  35.             /* <opcode> ^"<functionname>" ^[paramlist] <returntype> ^<OpcodeRec> */
  36.  
  37.         /* Debugging function.  If executed, it traps and presents the error message */
  38.         /* to the user.  It expects there to be a boolean on the stack which indicates */
  39.         /* whether the user can resume or not.  The boolean is popped if user resumes. */
  40.         epErrorTrap,  /* <opcode> ^"<errorstring>" */
  41.  
  42.         /* Branch instructions.  The parameter is the absolute address within the */
  43.         /* current block of code.  Conditional branch instructions test and pop */
  44.         /* the top of stack */
  45.         epBranchUnconditional,  /* <opcode> <branchoffset> */
  46.         epBranchIfZero,
  47.         epBranchIfNotZero,
  48.  
  49.         /* calling conventions:  first, push a word on to reserve a place for the */
  50.         /* return value.  next, push the parameters on.  then call the function (which */
  51.         /* pushes the return address on).  the function returns and pops the return */
  52.         /* address off.  then the function pops the parameters off from under return addr. */
  53.         /* Return from subroutine.  This instruction marks the end of code.  The */
  54.         /* address to jump to is contained in the top of the stack.  This address is */
  55.         /* popped off the stack and execution resumes at the new address. */
  56.         epReturnFromSubroutine,  /* <opcode> */
  57.  
  58.         /* Intrinsic operators.  for binary operators, the right hand operand is on */
  59.         /* top of the stack, and one word is popped.  for unary operators, no words */
  60.         /* are popped */
  61.         epOperationBooleanEqual,
  62.         epOperationBooleanNotEqual,
  63.         epOperationBooleanAnd,
  64.         epOperationBooleanOr,
  65.         epOperationBooleanXor,
  66.         epOperationBooleanNot,
  67.         epOperationBooleanToInteger,
  68.         epOperationBooleanToFloat,
  69.         epOperationBooleanToDouble,
  70.         epOperationBooleanToFixed,
  71.         epOperationIntegerAdd,
  72.         epOperationIntegerSubtract,
  73.         epOperationIntegerNegation,
  74.         epOperationIntegerMultiply,
  75.         epOperationIntegerDivide,
  76.         epOperationIntegerImpreciseDivide,
  77.         epOperationIntegerModulo,
  78.         epOperationIntegerShiftLeft,
  79.         epOperationIntegerShiftRight,
  80.         epOperationIntegerGreaterThan,
  81.         epOperationIntegerLessThan,
  82.         epOperationIntegerGreaterThanOrEqual,
  83.         epOperationIntegerLessThanOrEqual,
  84.         epOperationIntegerEqual,
  85.         epOperationIntegerNotEqual,
  86.         epOperationIntegerAbs,
  87.         epOperationIntegerToBoolean,
  88.         epOperationIntegerToFloat,
  89.         epOperationIntegerToDouble,
  90.         epOperationIntegerToFixed,
  91.         epOperationIntegerAnd,
  92.         epOperationIntegerOr,
  93.         epOperationIntegerXor,
  94.         epOperationIntegerNot,
  95.         epOperationTestIntegerNegative,
  96.         epOperationGetSignInteger,
  97.         epOperationFloatAdd,
  98.         epOperationFloatSubtract,
  99.         epOperationFloatNegation,
  100.         epOperationFloatMultiply,
  101.         epOperationFloatDivide,
  102.         epOperationFloatShiftLeft,
  103.         epOperationFloatShiftRight,
  104.         epOperationFloatGreaterThan,
  105.         epOperationFloatLessThan,
  106.         epOperationFloatGreaterThanOrEqual,
  107.         epOperationFloatLessThanOrEqual,
  108.         epOperationFloatEqual,
  109.         epOperationFloatNotEqual,
  110.         epOperationFloatAbs,
  111.         epOperationFloatToBoolean,
  112.         epOperationFloatToInteger,
  113.         epOperationFloatToDouble,
  114.         epOperationFloatToFixed,
  115.         epOperationTestFloatNegative,
  116.         epOperationGetSignFloat,
  117.         epOperationDoubleAdd,
  118.         epOperationDoubleSubtract,
  119.         epOperationDoubleNegation,
  120.         epOperationDoubleMultiply,
  121.         epOperationDoubleDivide,
  122.         epOperationDoubleShiftLeft,
  123.         epOperationDoubleShiftRight,
  124.         epOperationDoubleGreaterThan,
  125.         epOperationDoubleLessThan,
  126.         epOperationDoubleGreaterThanOrEqual,
  127.         epOperationDoubleLessThanOrEqual,
  128.         epOperationDoubleEqual,
  129.         epOperationDoubleNotEqual,
  130.         epOperationDoubleAbs,
  131.         epOperationDoubleToBoolean,
  132.         epOperationDoubleToInteger,
  133.         epOperationDoubleToFloat,
  134.         epOperationDoubleToFixed,
  135.         epOperationDoubleSin,
  136.         epOperationDoubleCos,
  137.         epOperationDoubleTan,
  138.         epOperationDoubleAsin,
  139.         epOperationDoubleAcos,
  140.         epOperationDoubleAtan,
  141.         epOperationDoubleLn,
  142.         epOperationDoubleExp,
  143.         epOperationDoubleSqrt,
  144.         epOperationDoubleSqr,
  145.         epOperationDoublePower,
  146.         epOperationTestDoubleNegative,
  147.         epOperationGetSignDouble,
  148.         epOperationFixedAdd,
  149.         epOperationFixedSubtract,
  150.         epOperationFixedNegation,
  151.         epOperationFixedMultiply,
  152.         epOperationFixedDivide,
  153.         epOperationFixedShiftLeft,
  154.         epOperationFixedShiftRight,
  155.         epOperationFixedGreaterThan,
  156.         epOperationFixedLessThan,
  157.         epOperationFixedGreaterThanOrEqual,
  158.         epOperationFixedLessThanOrEqual,
  159.         epOperationFixedEqual,
  160.         epOperationFixedNotEqual,
  161.         epOperationFixedAbs,
  162.         epOperationFixedToBoolean,
  163.         epOperationFixedToInteger,
  164.         epOperationFixedToFloat,
  165.         epOperationFixedToDouble,
  166.         epOperationFixedAnd,
  167.         epOperationFixedOr,
  168.         epOperationFixedXor,
  169.         epOperationTestFixedNegative,
  170.         epOperationGetSignFixed,
  171.         /* additional operators for converting the data type that isn't on top of stack */
  172.         epOperationBooleanToIntegerBuried,  /* <opcode> <stackindex> */
  173.         epOperationBooleanToFloatBuried,
  174.         epOperationBooleanToDoubleBuried,
  175.         epOperationBooleanToFixedBuried,
  176.         epOperationIntegerToBooleanBuried,
  177.         epOperationIntegerToFloatBuried,
  178.         epOperationIntegerToDoubleBuried,
  179.         epOperationIntegerToFixedBuried,
  180.         epOperationFloatToBooleanBuried,
  181.         epOperationFloatToIntegerBuried,
  182.         epOperationFloatToDoubleBuried,
  183.         epOperationFloatToFixedBuried,
  184.         epOperationDoubleToBooleanBuried,
  185.         epOperationDoubleToIntegerBuried,
  186.         epOperationDoubleToFloatBuried,
  187.         epOperationDoubleToFixedBuried,
  188.         epOperationFixedToBooleanBuried,
  189.         epOperationFixedToIntegerBuried,
  190.         epOperationFixedToFloatBuried,
  191.         epOperationFixedToDoubleBuried,
  192.  
  193.         /* these obtain the size of the array on top of stack, replacing the array */
  194.         /* with the size value. */
  195.         epGetBooleanArraySize,  /* <opcode> */
  196.         epGetIntegerArraySize,
  197.         epGetFloatArraySize,
  198.         epGetDoubleArraySize,
  199.         epGetFixedArraySize,
  200.  
  201.         /* array is pushed on stack, then size is pushed on stack.  this resizes */
  202.         /* the array, and pops the new size word. */
  203.         epResizeBooleanArray2,  /* <opcode> */
  204.         epResizeIntegerArray2,
  205.         epResizeFloatArray2,
  206.         epResizeDoubleArray2,
  207.         epResizeFixedArray2,
  208.  
  209.         /* store values on stack.  the value on top is stored BUT NOT POPPED */
  210.         epStoreIntegerOnStack,  /* <opcode> <stackindex> */
  211.         epStoreFloatOnStack,
  212.         epStoreDoubleOnStack,
  213.         epStoreArrayOnStack,
  214.         /* load values.  the value is loaded and pushed onto the stack */
  215.         epLoadIntegerFromStack,
  216.         epLoadFloatFromStack,
  217.         epLoadDoubleFromStack,
  218.         epLoadArrayFromStack,
  219.  
  220.         /* allocate one empty cell on the stack */
  221.         epStackAllocate, /* <opcode> */
  222.  
  223.         /* deallocate one cell from the stack */
  224.         epStackPop,  /* <opcode> */
  225.  
  226.         /* deallocate several cells from the stack */
  227.         epStackPopMultiple,  /* <opcode> <numstackwords> */
  228.  
  229.         /* deallocate some cells from underneath the top cell */
  230.         epStackDeallocateUnder,  /* <opcode> <numwords> */
  231.  
  232.         /* duplicate word on top of stack */
  233.         epDuplicate,  /* <opcode> */
  234.  
  235.         /* no op */
  236.         epNop,  /* <opcode> */
  237.  
  238.         /* allocate array on stack; size is on stack to start out with */
  239.         epMakeBooleanArray,  /* <opcode> */
  240.         epMakeIntegerArray,
  241.         epMakeFloatArray,
  242.         epMakeDoubleArray,
  243.         epMakeFixedArray,
  244.  
  245.         /* store value into array.  value is pushed on stack, then array ref, then */
  246.         /* array subscript.  ref and subscript are popped; value remains */
  247.         epStoreBooleanIntoArray2,  /* <opcode> */
  248.         epStoreIntegerIntoArray2,
  249.         epStoreFloatIntoArray2,
  250.         epStoreDoubleIntoArray2,
  251.         epStoreFixedIntoArray2,
  252.  
  253.         /* load from array.  array is on stack, then subscript is on top of that.  both */
  254.         /* are popped and the value is pushed on the stack. */
  255.         epLoadBooleanFromArray2,  /* <opcode> */
  256.         epLoadIntegerFromArray2,
  257.         epLoadFloatFromArray2,
  258.         epLoadDoubleFromArray2,
  259.         epLoadFixedFromArray2,
  260.  
  261.         /* load an immediate value on to the stack */
  262.         epLoadImmediateInteger, /* <opcode> <integer>; also used for boolean & fixed */
  263.         epLoadImmediateFloat, /* <opcode> ^<float> */
  264.         epLoadImmediateDouble, /* <opcode> ^<double> */
  265.         epLoadImmediateNILArray, /* <opcode> */
  266.  
  267.         /* get a fixed array corresponding to the named sample */
  268.         epGetSampleLeftArray, /* <opcode> ^"<namestring>" */
  269.         epGetSampleRightArray, /* <opcode> ^"<namestring>" */
  270.         epGetSampleMonoArray, /* <opcode> ^"<namestring>" */
  271.         epGetWaveTableArray, /* <opcode> ^"<namestring>" */
  272.         /* get attributes for wave tables */
  273.         epGetWaveTableFrames, /* <opcode> ^"<namestring>" */
  274.         epGetWaveTableTables, /* <opcode> ^"<namestring>" */
  275.  
  276.         /* print string literal */
  277.         epPrintString, /* <opcode> ^"<string>" */
  278.         /* print value, popped from top of stack */
  279.         epPrintBool, /* <opcode> */
  280.         epPrintDouble /* <opcode> */
  281.     } Pcodes;
  282.  
  283. /* these are the data types recognized by the system */
  284. typedef enum
  285.     {
  286.         eBoolean EXECUTE(= -5152),
  287.         eInteger,
  288.         eFloat,
  289.         eDouble,
  290.         eFixed,
  291.         eArrayOfBoolean,
  292.         eArrayOfInteger,
  293.         eArrayOfFloat,
  294.         eArrayOfDouble,
  295.         eArrayOfFixed
  296.     } DataTypes;
  297.  
  298. union OpcodeRec;
  299. typedef union OpcodeRec OpcodeRec;
  300.  
  301. #ifdef SHOW_ME_OPCODEREC
  302. /* publicly declared so we can break up the pcode stuff */
  303. union OpcodeRec
  304.     {
  305.         Pcodes                            Opcode;
  306.         double*                            ImmediateDouble;
  307.         float*                            ImmediateFloat;
  308.         long                                ImmediateInteger;
  309.         char*                                ImmediateString;
  310.         union OpcodeRec*        FunctionOpcodeRecPtr;
  311.         DataTypes*                    DataTypeArray;
  312.     };
  313. #endif
  314.  
  315. struct PcodeRec;
  316. typedef struct PcodeRec PcodeRec;
  317.  
  318. /* allocate a new pseudocode block */
  319. PcodeRec*                    NewPcode(void);
  320.  
  321. /* release the memory associated with the pseudocode block */
  322. void                            DisposePcode(PcodeRec* Pcode);
  323.  
  324. /* find out what the address of the next instruction will be */
  325. long                            PcodeGetNextAddress(PcodeRec* Pcode);
  326.  
  327. /* get the opcode array for a pcode (so we don't have to declare Pcode publicly.) */
  328. OpcodeRec*                GetOpcodeFromPcode(PcodeRec* Pcode);
  329.  
  330. /* get the number of cells in the array */
  331. long                            GetNumberOfValidCellsInPcode(PcodeRec* Pcode);
  332.  
  333. /* put a new opcode array into the pcode.  this does not allocate or release any */
  334. /* memory, but merely updates the pointer.  it should not be called by anyone */
  335. /* except the optimizer.   after the optimizer is done, it resizes the array to */
  336. /* be exactly the size we need. */
  337. void                            UpdateOpcodeInPcode(PcodeRec* Pcode, OpcodeRec* NewOpcodeArray,
  338.                                         long NewNumInstructions);
  339.  
  340. /* add a pcode instruction or an operand value */
  341. MyBoolean                    AddPcodeInstruction(PcodeRec* Pcode, Pcodes Opcode, long* Index);
  342. MyBoolean                    AddPcodeOperandDouble(PcodeRec* Pcode, double ImmediateData);
  343. MyBoolean                    AddPcodeOperandFloat(PcodeRec* Pcode, float ImmediateData);
  344. MyBoolean                    AddPcodeOperandInteger(PcodeRec* Pcode, long ImmediateData);
  345. MyBoolean                    AddPcodeOperandString(PcodeRec* Pcode, char* String, long Length);
  346. MyBoolean                    AddPcodeOperandDataTypeArray(PcodeRec* Pcode, DataTypes* DataTypeArray);
  347.  
  348. /* resolve a pcode branch whose destination was not known earlier but now is */
  349. void                            ResolvePcodeBranch(PcodeRec* Pcode, long Where, long Destination);
  350.  
  351. /* unlink references to a function which is soon going to disappear. */
  352. void                            PcodeUnlink(PcodeRec* Function, char* DeadFuncName,
  353.                                         PcodeRec* DeadFuncCode);
  354.  
  355. /* get the number of words for the specified instruction opcode */
  356. long                            GetInstructionLength(Pcodes OpcodeWord);
  357.  
  358. #endif
  359.